/**
 * 
 */
package design_pattern.iterator;

/**
 * @author linzq
 * 
 */
public class ConcreteIterator implements Iterator {

  private ConcreteAggregate agg;

  private int index = 0;

  private int size = 0;

  public ConcreteIterator(ConcreteAggregate agg) {
    this.agg = agg;
    this.index = 0;
    this.size = agg.size();
  }

  @Override
  public boolean isFirst() {
    if (index == 0) {
      return true;
    }
    return false;
  }

  @Override
  public boolean isLast() {
    if (index == size - 1) {
      return true;
    }
    return false;
  }

  @Override
  public Object current() {
    return agg.getElement(index);
  }

  @Override
  public boolean hasNext() {
    if (index < size) {
      return true;
    }
    return false;
  }

  @Override
  public Object next() {
    if (index < size) {
      return agg.getElement(index++);
    }
    return null;
  }

  @Override
  public void first() {
    index = 0;
  }

  @Override
  public void last() {
    index = size - 1;
  }

}
